import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.Comparator;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;

public class HJ98 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while((line = br.readLine()) != null){
            String[] commands = line.split(";");
            AutoMat automat = new AutoMat();     // 自动售货机
            for(String command: commands) {
                if(command.startsWith("r")){
                    // 初始化自动贩卖机
                    automat = initialAutoMat(command);
                    System.out.println("S001:Initialization is successful");
                }else if(command.startsWith("p")){
                    // 投币
                    int coin = Integer.parseInt(command.split(" ")[1]);
                    if(!automat.moneyNums.keySet().contains(coin)){
                        // 不支持此面额的纸币
                        System.out.println("E002:Denomination error");
                    }else if(coin > 2 && automat.moneyNums.get(1) + 2*automat.moneyNums.get(2) < coin){
                        // 零钱不足
                        System.out.println("E003:Change is not enough, pay fail");
                    }else if(automat.isEmpty()){
                        // 没有货了
                        System.out.println("E005:All the goods sold out");
                    }else{
                        // 投币成功，余额增加，相应面额张数也增加
                        automat.balance += coin;
                        automat.moneyNums.put(coin, automat.moneyNums.get(coin) + 1);
                        System.out.println("S002:Pay success,balance=" + automat.balance);
                    }
                }else if(command.startsWith("b")){
                    // 购买
                    String product = command.split(" ")[1];
                    if(!automat.goodsNums.keySet().contains(product)){
                        // 没有这个商品
                        System.out.println("E006:Goods does not exist");
                    }else if(automat.goodsNums.get(product) == 0){
                        // 这个商品售罄了
                        System.out.println("E007:The goods sold out");
                    }else{
                        if(automat.balance >= automat.goodsPrice.get(product)){
                            // 购买成功，相应商品减少一个，余额也做相应地减少
                            int price = automat.goodsPrice.get(product);
                            automat.goodsNums.put(product, automat.goodsNums.get(product) - 1);
                            automat.balance -= price;
                            System.out.println("S003:Buy success,balance=" + automat.balance);
                        }else{
                            // 买不起
                            System.out.println("E008:Lack of balance");
                        }
                    }
                }else if(command.startsWith("c")){
                    // 退币
                    if(automat.balance == 0){
                        // 没有钱可以退
                        System.out.println("E009:Work failure");
                    }else{
                        automat.returns();
                        automat.balance = 0;    // 退钱后余额清零
                    }
                }else{
                    // 查询
                    if(command.charAt(1) != ' ') {
                        System.out.println("E010:Parameter error");
                        continue;
                    }
                    int op = Integer.parseInt(command.substring(1));
                    if(op == 0){
                        // 输出商品余量信息
                        automat.printGoodsInfo();
                    }else if(op == 1){
                        // 输出纸币余量信息
                        automat.printMoneyInfo();
                    }else{
                        System.out.println("E010:Parameter error");
                    }
                }
            }
        }
    }

    private static AutoMat initialAutoMat(String command) {
        String[] params = command.split(" ");
        AutoMat automat = new AutoMat(params[1].split("-"), params[2].split("-"));
        return automat;
    }
}

class AutoMat {
    // 商品数量
    public TreeMap<String, Integer> goodsNums = new TreeMap<>();
    // 商品单价
    public TreeMap<String, Integer> goodsPrice = new TreeMap<>();
    // 不同纸币的数量
    public TreeMap<Integer, Integer> moneyNums = new TreeMap<>();
    // 余额
    public int balance = 0;
    public AutoMat() {}

    public AutoMat(String[] goodsnums, String[] moneynums) {
        // 各类商品的数量
        goodsNums.put("A1", Integer.parseInt(goodsnums[0]));
        goodsNums.put("A2", Integer.parseInt(goodsnums[1]));
        goodsNums.put("A3", Integer.parseInt(goodsnums[2]));
        goodsNums.put("A4", Integer.parseInt(goodsnums[3]));
        goodsNums.put("A5", Integer.parseInt(goodsnums[4]));
        goodsNums.put("A6", Integer.parseInt(goodsnums[5]));
        // 各类纸币的数量
        moneyNums.put(1, Integer.parseInt(moneynums[0]));
        moneyNums.put(2, Integer.parseInt(moneynums[1]));
        moneyNums.put(5, Integer.parseInt(moneynums[2]));
        moneyNums.put(10, Integer.parseInt(moneynums[3]));
        // 商品单价
        goodsPrice.put("A1", 2);
        goodsPrice.put("A2", 3);
        goodsPrice.put("A3", 4);
        goodsPrice.put("A4", 5);
        goodsPrice.put("A5", 8);
        goodsPrice.put("A6", 6);
    }

    public boolean isEmpty(){
        return goodsNums.get("A1") + goodsNums.get("A2") + goodsNums.get("A3") + goodsNums.get("A4") + goodsNums.get("A5") + goodsNums.get("A6") == 0;
    }

    public void returns() {
        int oneCnt = 0, twoCnt = 0, fiveCnt = 0, tenCnt = 0;
        // 为了保证退纸币的张数尽可能少，从大面额的开始退
        while(balance >= 10 && moneyNums.get(10) > 0){
            balance -= 10;
            tenCnt ++;
            moneyNums.put(10, moneyNums.get(10) - 1);
        }
        while(balance >= 5 && moneyNums.get(5) > 0){
            balance -= 5;
            fiveCnt ++;
            moneyNums.put(5, moneyNums.get(5) - 1);
        }
        while(balance >= 2 && moneyNums.get(2) > 0){
            balance -= 2;
            twoCnt ++;
            moneyNums.put(2, moneyNums.get(2) - 1);
        }
        while(balance >= 1 && moneyNums.get(1) > 0){
            balance --;
            oneCnt ++;
            moneyNums.put(1, moneyNums.get(1) - 1);
        }
        System.out.println("1 yuan coin number=" + oneCnt);
        System.out.println("2 yuan coin number=" + twoCnt);
        System.out.println("5 yuan coin number=" + fiveCnt);
        System.out.println("10 yuan coin number=" + tenCnt);
    }

    public void printGoodsInfo() {
        List<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(goodsNums.entrySet());
        // 按商品余量排序
        Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
                return o2.getValue().compareTo(o1.getValue());
            }
        });
        // 输出：商品 单价 余量
        for(Entry<String, Integer> e: list)
            System.out.println(e.getKey() + " " + goodsPrice.get(e.getKey()) + " " + e.getValue());
    }

    public void printMoneyInfo(){
        for(int money: moneyNums.keySet())
            System.out.println(money + " yuan coin number=" + moneyNums.get(money));
    }
}